from scapy.all import *
import time
def capture(x):
    if b'HTTP/' in x.lastlayer().original and x.lastlayer().original[0:4] != b'HTTP':
        print('dst ip:', x.payload.dst)
        print('request body:', x.lastlayer().original)


def main():
    sniff(filter="tcp", prn=lambda x: capture(x))


# if __name__ == '__main__':
#     main()


def syn():
    scrIP = '192.168.0.197'
    srcPort = 23345
    desIP = '192.168.1.6'
    desPort = 8000
    data="wangxiaoyan521"
    ip = IP(src=scrIP, dst=desIP)
    tcp = TCP(sport=srcPort, dport=desPort, seq=13131342, flags='S')
    pkg = ip / tcp /data

    # c->s syn
    res = send(pkg,count=100,inter=1)
    # res.display()
# syn()


# ping =sr1(IP(dst="192.168.1.6",ttl=(1,4))/ICMP())
# print(ping[1].show)
#
# print('-'*80)


# sync = sr1(IP(dst='192.168.1.170')/TCP(dport=139,flags='S'))
# print(sync[0].show())
# print(sync[1].display())
#
# print(sync.payload)
ip1 =IP(ttl=10)
print(ip1.show())
ip1.ttl=24
ip1.src='192.168.1.170'
print(ip1.show())
ip1[IP].show()







# packets =sniff( filter="tcp", count=20)
# for p in packets:
#     if 'TCP' in p:
#         print('=' * 78)
#         Ether_name = p.name
#         Ether_dst = p.dst
#
#         Ether_src = p.src
#         IP_name = p.payload.name
#         # IP_proto = p.payload.proto
#         IP_src = p.payload.src
#         IP_dst = p.payload.dst
#
#         print(Ether_name)
#         print('dst : ' + Ether_dst)
#         print('src : ' + Ether_src)
#
#         print(IP_name)
#         # print('protcol : ' + IP_proto)
#         print('src : ' + IP_src)
#         print('dst : ' + IP_dst)